<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="portal" uri="/WEB-INF/portal.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
 <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/scooter/include/common-base.jsp"%>
  <title>密码修改-${titleName}</title>
  <!-- Tell the browser to be responsive to screen width -->
<script type="text/javascript" src="${ctx}/js/jquery-tools.min.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery/jquery.validate.min.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery/jquery-validate-methods.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery/messages_cn.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery/formValidator_min.js"  charset="UTF-8"></script>
<script type="text/javascript" src="${ctx}/js/jquery/formValidatorRegex.js"  charset="UTF-8"></script>
<script type="text/javascript" src="${ctx}/js/jquery-md5-min.js"></script>
<script type="text/javascript" src="${ctx}/js/uct/uc.js"  charset="UTF-8"></script>
</head>
<body  class="hold-transition ${sysUserColor} sidebar-mini">
<script type="text/javascript">
var clickMenu = "my-user-edit-pass";
$(function(){
	validator();
});

function doSumbit(){
	$("#myForm").submit();
}
function validator(){
    var mark = $("#myForm").validate({
       submitHandler: function(form){//表单提交句柄,为一回调函数，带一个参数：form
    	  // alert($("#password").val());
        	if($("#password").val()==""){
        		layer.alert("输入新密码");
			 	return;
			}
			if($("#password2").val()==""){
				alert("输入重复密码");
				return;
			}
			if($("#oldpassword").val()==$("#password2").val()){
				layer.alert("新旧密码不能一样");
				return;
			}
			if($("#password").val()!=$("#password2").val()){
				layer.alert("两次输入的密码不一致");
				return;
			}
			$("#userPass").val($("#oldpassword").val().md5());
			$("#newPass").val($("#password").val().md5());
			$("#newPass2").val($("#password2").val().md5());
     	   var formUrl =ctx+'/res/uct/editPwd';
     	   var index_submit = layer.confirm("确定要保存此信息吗？", {btn: ["是","否"],closeBtn: 0,offset: "220px"}
   			, function(){
   			layer.close(index_submit);
					var result = $.platform.submit({formId:'myForm',dataType:'json',url:formUrl});
					opDone(result.flag,result.msg)
			    });
      },
      messages:{}
  });
	return mark;
}
function opDone(flag,msg){
	var userType = "${loginUser.userType}";
	if(flag=="T"){
			layer.alert("修改成功，请重新登录！");
			var result;
		   $.ajax({url:ctx+'/res/uct/logout',type: 'POST',cache: false,async:false,dataType:'json',
				   success: function(data){result = data;}
			});
			location.href=ctx+"/logout";
		}else{
			layer.alert(msg);
		}
	}
function checkUserPwd(){
    if($("#checkUserPass").attr("checked")=="checked"){
       $(".isupdPass").show();
       $("#checkUserPass").val("1");
       $('#oldpassword').attr('required', true);
       $('#password').attr('required', true);
       $('#password2').attr('required', true);
    }else{
      $(".isupdPass").hide();
      $("#checkUserPass").val("0");
      $('#oldpassword').attr('required', false);
      $('#password').attr('required', false);
      $('#password2').attr('required', false);
    }
}
</script>
<div class="wrapper">

 <!-- top start -->
  <%@include file="/common/scooter/top-user.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/scooter/left-user.jsp" %>
  <!-- left end -->

	<div class="content-wrapper">
    <!-- Main start -->
	<section class="content">
 <div class="panel">
  	<div class="panel-heading">
  		<h4 class="fx2"><i class="fa fa-user-plus"></i> 密码修改</h4>
  	</div>
  	<div class="panel-body">
        <form id="myForm"  action="" method="post">
          <input type="hidden" id="userid" name="userid"  value="${loginUser.userId }"/>
          <input type="hidden" id="username" name="username"  value="${loginUser.userEname}"/>
          <input type="hidden"  name="checkUserPass" value="1" />
          <input type="hidden"  name="userPass" id="userPass" />
          <input type="hidden"  name="newPass" id="newPass" />
          <input type="hidden"  name="newPass2" id="newPass2" />

         <table cellpadding="0" cellspacing="0" border="0" width="100%" class="table table-bordered">
            <tr>
              <th style="width:140px;" class="text-right">用户名：</th>
              <td><span class="col-sm-4">${loginUser.userEname}</span></td>
            </tr>
			<tr class="isupdPass">
	              <th  class="text-right">旧密码：</th>
	              <td>
	              	<span class="col-sm-4">
	              		<input class="form-control" type="password" id="oldpassword" name="userPass" required="true" placeholder="输入旧的密码" isPwd="true" />
	              	</span>
	              </td>
	            </tr>
	            <tr class="isupdPass">
	              <th  class="text-right">新密码：</th>
	              <td>
					<span class="col-sm-4">
	              		<input class="form-control" type="password" id="password" name="newPass"  required="true" placeholder="新密码不能和旧密码重复" isPwd="true"/>
	              	</span>
	              </td>
	            </tr>
	            <tr class="isupdPass">
	              <th  class="text-right">确认新密码：</th>
	              <td>
	              	<span class="col-sm-4">
	              		<input class="form-control" type="password" id="password2" name="newPass2" required="true" placeholder="再次输入新密码" isPwd="true" />
	              	</span>
	              </td>
	            </tr>
	            <tr>
	              <th  class="text-right">验证码：</th>
	              <td class="rand">
	              	<span class="col-sm-4">
	              		<input  class="form-control"  type="text" style="width:150px;" name="rand" id="rand"  required="true" maxlength="4" onclick="if(document.getElementById('verifyCode').style.visibility=='hidden'){viewVerifyCode();}"><img border=0 id="verifyCode" src="" onclick="viewVerifyCode();" style="visibility:hidden;" align="absmiddle"/>
				      	<script>viewVerifyCode();</script>
				   </span>
				   </td>
	            </tr>
				<tr>
				<td>&nbsp;</td>
				<td align="left"><input type="button" onclick="doSumbit()"  name="button" id="button"  class="btn btn-danger" value="提交保存"/></td>
				</tr>
          </table>
        </form>

        <!--表单结束 -->
      </div>
    </div>
    <!--主体内容结束-->
   </section>
  </div>
   <!-- foot start -->
  <%@include file="/common/scooter/foot-user.jsp" %>
  <!-- foot start -->

</body>
</html>
